﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Ext.Net;

public partial class UserControl_DeptComboxTree : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void NodeLoad(object sender, NodeLoadEventArgs e)
    {
        //Ext.Msg.Alert("", "aaa").Show();
        //每当用户点击节点的时候 
        if (e.NodeID == "0")//绑定group
        {
            //清空节点信息
            e.Nodes.Clear();
            DataTable tmpDt = CommonLib.BLL.SYS_DEPT.GetListSub(" dept_id='00' and  del_flag =0 ", "dept_id").Tables[0];
            if (tmpDt.Rows.Count == 1)
            {
                Ext.Net.TreeNode root = new Ext.Net.TreeNode();
                root.Text = tmpDt.Rows[0]["dept_name"].ToString();
                root.NodeID = tmpDt.Rows[0]["dept_id"].ToString();
                root.Expanded = true;
                root.IconCls = "no-icon";
                if (tmpDt.Rows[0]["leaf"].ToString() == "0")
                    root.Leaf = true;
                root.Draggable = true;
                e.Nodes.Add(root);

                DataTable TreeData = CommonLib.BLL.SYS_DEPT.GetListSub(" del_flag =0 and ltrim(rtrim(dept_id)) like '" + tmpDt.Rows[0]["dept_id"].ToString().Trim() + "__' ", "dept_id").Tables[0];
                for (int i = 0; i < TreeData.Rows.Count; i++)
                {
                    AsyncTreeNode asyncNode = new AsyncTreeNode();
                    asyncNode.Text = TreeData.Rows[i]["dept_name"].ToString();
                    asyncNode.NodeID = TreeData.Rows[i]["dept_id"].ToString();
                    asyncNode.IconCls = "no-icon";
                    if (TreeData.Rows[i]["leaf"].ToString() == "0")
                        asyncNode.Leaf = true;
                    root.Nodes.Add(asyncNode);
                }
            }
        }
        else
        {
            if (!string.IsNullOrEmpty(e.NodeID))
            {
                DataTable TreeData = CommonLib.BLL.SYS_DEPT.GetListSub(" del_flag =0 and ltrim(rtrim(dept_id)) like '" + e.NodeID.Trim() + "__' ", "dept_id").Tables[0];
                for (int i = 0; i < TreeData.Rows.Count; i++)
                {
                    AsyncTreeNode asyncNode = new AsyncTreeNode();
                    asyncNode.Text = TreeData.Rows[i]["dept_name"].ToString();
                    asyncNode.NodeID = TreeData.Rows[i]["dept_id"].ToString();
                    asyncNode.IconCls = "no-icon";
                    if (TreeData.Rows[i]["leaf"].ToString() == "0")
                        asyncNode.Leaf = true;
                    e.Nodes.Add(asyncNode);
                }
            }
        }

    }

}
